<!doctype html>



  


<html class="theme-next mist use-motion" lang="en">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="svg | viewport | view box," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="学习svg，除了掌握基本的图形元素，更要清楚svg元素的大小与svg内部图形大小的关系，svg图像的 viewport 和 view box 共同设置了图像可见部分的尺寸。现在我们一起学习下 viewport 和 view box 的知识，也许清不清楚这些知识对svg元素的使用不会产生多大的影响，但涉及到复杂图形的时候，了解这些知识会有助于我们更快速、更精准的控制元素，并且减轻维护成本。 1. T">
<meta name="keywords" content="svg | viewport | view box">
<meta property="og:type" content="article">
<meta property="og:title" content="svg_viewport&amp;viewbox">
<meta property="og:url" content="http://yoursite.com/2017/03/04/svg-viewport-viewbox/index.html">
<meta property="og:site_name" content="Ji Xiang&#39;s blog">
<meta property="og:description" content="学习svg，除了掌握基本的图形元素，更要清楚svg元素的大小与svg内部图形大小的关系，svg图像的 viewport 和 view box 共同设置了图像可见部分的尺寸。现在我们一起学习下 viewport 和 view box 的知识，也许清不清楚这些知识对svg元素的使用不会产生多大的影响，但涉及到复杂图形的时候，了解这些知识会有助于我们更快速、更精准的控制元素，并且减轻维护成本。 1. T">
<meta property="og:locale" content="en">
<meta property="og:image" content="http://o7bp9e1ec.bkt.clouddn.com/1488696584964">
<meta property="og:image" content="http://o7bp9e1ec.bkt.clouddn.com/1488691161226">
<meta property="og:image" content="http://o7bp9e1ec.bkt.clouddn.com/1488693398271">
<meta property="og:image" content="http://o7bp9e1ec.bkt.clouddn.com/1488693927989">
<meta property="og:image" content="http://o7bp9e1ec.bkt.clouddn.com/1488694387507">
<meta property="og:image" content="http://o7bp9e1ec.bkt.clouddn.com/1488694788943">
<meta property="og:updated_time" content="2018-11-18T02:59:33.030Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="svg_viewport&amp;viewbox">
<meta name="twitter:description" content="学习svg，除了掌握基本的图形元素，更要清楚svg元素的大小与svg内部图形大小的关系，svg图像的 viewport 和 view box 共同设置了图像可见部分的尺寸。现在我们一起学习下 viewport 和 view box 的知识，也许清不清楚这些知识对svg元素的使用不会产生多大的影响，但涉及到复杂图形的时候，了解这些知识会有助于我们更快速、更精准的控制元素，并且减轻维护成本。 1. T">
<meta name="twitter:image" content="http://o7bp9e1ec.bkt.clouddn.com/1488696584964">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/03/04/svg-viewport-viewbox/"/>





  <title> svg_viewport&viewbox | Ji Xiang's blog </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="en">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">Ji Xiang's blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
    
      <p class="site-subtitle">Walk step by step and learn everyday</p>
    
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            Tags
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/03/04/svg-viewport-viewbox/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="Ji Xiang">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="http://o7bp9e1ec.bkt.clouddn.com/1485173143816">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="Ji Xiang's blog">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="Ji Xiang's blog" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                svg_viewport&viewbox
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2017-03-04T22:27:04+08:00">
                2017-03-04
              </time>
            

            

            
          </span>

          

          
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>学习svg，除了掌握基本的图形元素，更要清楚svg元素的大小与svg内部图形大小的关系，svg图像的 viewport 和 view box 共同设置了图像可见部分的尺寸。现在我们一起学习下 viewport 和 view box 的知识，也许清不清楚这些知识对svg元素的使用不会产生多大的影响，但涉及到复杂图形的时候，了解这些知识会有助于我们更快速、更精准的控制元素，并且减轻维护成本。</p>
<h3 id="1-The-Viewport-and-View-Box"><a href="#1-The-Viewport-and-View-Box" class="headerlink" title="1. The Viewport and View Box"></a>1. The Viewport and View Box</h3><p><strong>viewport</strong> 是创建svg元素时给它设置的 width 和 height，决定了svg图像的可视区域。逻辑上svg图像可以无限大，但每次只有特定的区域是可视的，这个可视区域就是 viewport。你可以通过svg元素的 width 和 height 属性来指定 viewport 的大小：如</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">svg</span> <span class="attr">width</span>=<span class="string">"500"</span> <span class="attr">height</span>=<span class="string">"300"</span>&gt;</span><span class="tag">&lt;/<span class="name">svg</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>这个例子定义了一个宽500单位、高300单位的viewport。   </p>
<p><strong>view box</strong> 是 svg的一个属性，设置了内部图形的坐标系大小。   </p>
<p>更直观的解释是：viewport 就像是显示器，有固定的宽高，你只能在显示器屏幕的范围内观看影像，view box 设置了显示器里的影像通过何种比例显示出来。就像你看到一个大海，它也许只占了显示器里大小的1/4，但它实际的大小却是显示器的n倍。viewport 和 view box 指定了两个坐标系，内部的图形会根据这两个坐标系做适当的缩放来适应性的显示出来。</p>
<h3 id="2-svg坐标系单位"><a href="#2-svg坐标系单位" class="headerlink" title="2. svg坐标系单位"></a>2. svg坐标系单位</h3><p>如果你没有指定 width 和 height 属性的单位，那么单位会被默认为 px。你还可以使用 px 以外的单位，</p>
<table>
<thead>
<tr>
<th>单位</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>em</td>
<td>相对单位：相对于父元素字体大小</td>
</tr>
<tr>
<td>ex</td>
<td>相对单位：相对于字符 x 的高度(很少使用)</td>
</tr>
<tr>
<td>px</td>
<td>绝对单位，但相对于设备分辨率：像素</td>
</tr>
<tr>
<td>pt</td>
<td>绝对单位：点(1／72英寸)</td>
</tr>
<tr>
<td>pc</td>
<td>绝对单位：(1／6英寸)</td>
</tr>
<tr>
<td>cm</td>
<td>绝对单位：厘米</td>
</tr>
<tr>
<td>mm</td>
<td>绝对单位：毫米</td>
</tr>
<tr>
<td>in</td>
<td>绝对单位：英寸</td>
</tr>
</tbody>
</table>
<p>给svg元素设置的单位只会影响svg元素的大小(viewport)。svg图像里显示的svg图形元素的大小取决于你给每个图形设置的单位。如果没有指定单位，默认使用 px。</p>
<p>下面展示一个svg元素与svg图像里的图形设置不同单位的例子：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">svg</span> <span class="attr">width</span>=<span class="string">"10cm"</span> <span class="attr">height</span>=<span class="string">"10cm"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rect</span> <span class="attr">x</span>=<span class="string">"50"</span> <span class="attr">y</span>=<span class="string">"100"</span> <span class="attr">width</span>=<span class="string">"50"</span> <span class="attr">height</span>=<span class="string">"50"</span> <span class="attr">style</span>=<span class="string">"stroke: #000000; fill: none;"</span>&gt;</span><span class="tag">&lt;/<span class="name">rect</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rect</span> <span class="attr">x</span>=<span class="string">"100"</span> <span class="attr">y</span>=<span class="string">"100"</span> <span class="attr">width</span>=<span class="string">"50mm"</span> <span class="attr">height</span>=<span class="string">"50mm"</span> <span class="attr">style</span>=<span class="string">"stroke: #000000; fill: none;"</span>&gt;</span><span class="tag">&lt;/<span class="name">rect</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">svg</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>svg图像单单位是cm，两个rect元素有自己的单位：第一个没有指明单位，默认px；第二个使用了mm。结果如下：</p>
<p><img src="http://o7bp9e1ec.bkt.clouddn.com/1488696584964" alt="pic_1"></p>
<h3 id="3-The-View-Box"><a href="#3-The-View-Box" class="headerlink" title="3. The View Box"></a>3. The View Box</h3><p>你可以通过 viewBox 属性重新定义没有单位的坐标。注：view box属性不要带单位。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">svg</span> <span class="attr">width</span>=<span class="string">"500"</span> <span class="attr">height</span>=<span class="string">"200"</span> <span class="attr">viewBox</span>=<span class="string">"0 0 50 20"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rect</span> <span class="attr">x</span>=<span class="string">"20"</span> <span class="attr">y</span>=<span class="string">"10"</span> <span class="attr">width</span>=<span class="string">"10"</span> <span class="attr">height</span>=<span class="string">"5"</span> <span class="attr">style</span>=<span class="string">"stroke: #000000; fill: none;"</span>&gt;</span><span class="tag">&lt;/<span class="name">rect</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">svg</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>这个例子中我们创建了一个宽500px高200px的svg元素。viewBox属性有四个值 x y width height，这些值定义了svg元素的视区，x 和 y是视区的左上角坐标，width 和 height是视区的宽高。在这个例子中，视区从(0, 0)开始，宽高分别是50和20，这意味着宽500px、高200px的svg元素在内部使用的坐标系是从(0, 0)开始，到(50, 20)。换句话说，svg元素内部坐标系中的1单位相当于宽度500/50=10px、高度200/20=10px。这就是为什么x轴偏移20单位、y轴偏移10单位的矩形实际位置却是偏移到了(200px, 100px)处。因为内部坐标系中1单位相当于10px。</p>
<p>结果为：</p>
<p><img src="http://o7bp9e1ec.bkt.clouddn.com/1488691161226" alt="pic_2"></p>
<h3 id="4-Preserving-Aspect-Ratio"><a href="#4-Preserving-Aspect-Ratio" class="headerlink" title="4. Preserving Aspect Ratio"></a>4. Preserving Aspect Ratio</h3><p>如果 viewport 和 view box 没有使用相同的长宽比(repect ratio)，你需要指定浏览器如何显示svg图像，这时你需要svg元素的preserveAspectRatio属性。   </p>
<p>preserveAspectRatio属性由两个被空格分隔的值组成。第一个值设置view box在viewport中如何对齐，这个值由两部分组成；第二个值设置如何保留长宽比（如果需要的话）。   </p>
<p>第一个值由两部分组成：x轴的对其方式和y轴的对齐方式，下面是这两个值的列表：</p>
<table>
<thead>
<tr>
<th>值</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>xMin</td>
<td>将 view box 和 viewport 左边对齐</td>
</tr>
<tr>
<td>xMid</td>
<td>将 view box 和 viewport x轴中心对齐</td>
</tr>
<tr>
<td>xMax</td>
<td>将 view box 和 viewport 右边对齐</td>
</tr>
<tr>
<td>yMin</td>
<td>将 view box 和 viewport 上边对齐</td>
</tr>
<tr>
<td>yMid</td>
<td>将 view box 和 viewport y轴中心对齐</td>
</tr>
<tr>
<td>yMax</td>
<td>将 view box 和 viewport 下边对齐</td>
</tr>
</tbody>
</table>
<p>这两个部分可以通过驼峰命名的方式组合起来：xMinYMin。   </p>
<p>第二个值有三个值：</p>
<table>
<thead>
<tr>
<th>值</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>meet</td>
<td>保留长宽比并缩放 view box 以适应 viewport</td>
</tr>
<tr>
<td>slice</td>
<td>保留长宽比并把超出 viewport 的部分裁剪掉</td>
</tr>
<tr>
<td>none</td>
<td>不保留长宽比，缩放图像以将 view box 完全置入 viewport。长宽比被破坏</td>
</tr>
</tbody>
</table>
<p>这两个值之间需要有一个空格：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">preserveAspectRatio=&quot;xMidYMid meet&quot;</span><br><span class="line">preserveAspectRatio=&quot;xMinYMin slice&quot;</span><br></pre></td></tr></table></figure></p>
<p>接下来我们来看看不同的 preserveAspectRatio 属性值带来的效果。</p>
<h5 id="1"><a href="#1" class="headerlink" title="(1)."></a>(1).</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">svg</span> <span class="attr">width</span>=<span class="string">"500"</span> <span class="attr">height</span>=<span class="string">"75"</span> <span class="attr">viewBox</span>=<span class="string">"0 0 250 75"</span> <span class="attr">style</span>=<span class="string">"border: 1px solid #cccccc;"</span>&gt;</span></span><br><span class="line">    &lt;rect x="1" y="1" width="50" height="50" style="stroke: #000000; fill: none;"&lt;/rect&gt;</span><br><span class="line"><span class="tag">&lt;/<span class="name">svg</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p><img src="http://o7bp9e1ec.bkt.clouddn.com/1488693398271" alt="pic_3"></p>
<p>这种不设置 preserveAspectRatio 的情况与 xMidYMid meet 的效果相同，由此可推测浏览器会默认让图像以最合适、最舒服的方式显示出来。</p>
<h5 id="2"><a href="#2" class="headerlink" title="(2)."></a>(2).</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">svg</span> <span class="attr">width</span>=<span class="string">"500"</span> <span class="attr">height</span>=<span class="string">"75"</span> <span class="attr">viewBox</span>=<span class="string">"0 0 250 75"</span> <span class="attr">preserveAspectRatio</span>=<span class="string">"xMinYMin meet"</span> <span class="attr">style</span>=<span class="string">"border: 1px solid #cccccc;"</span>&gt;</span></span><br><span class="line">    &lt;rect x="1" y="1" width="50" height="50" style="stroke: #000000; fill: none;"&lt;/rect&gt;</span><br><span class="line"><span class="tag">&lt;/<span class="name">svg</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p><img src="http://o7bp9e1ec.bkt.clouddn.com/1488693927989" alt="pic_4"><br>这个例子中设置了 preserveAspectRatio 为 xMinYMin meet，这会确保长宽比是保留了的，view box 会调整大小来适应 viewport。所以，view box 根据两个长宽比中(500/250=2, 75/75=1)较小的比例进行缩放(width: 50*1=50, height: 50*1=50)，xMinYMin 使图形左上对齐。</p>
<h5 id="3"><a href="#3" class="headerlink" title="(3)."></a>(3).</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">svg</span> <span class="attr">width</span>=<span class="string">"500"</span> <span class="attr">height</span>=<span class="string">"75"</span> <span class="attr">viewBox</span>=<span class="string">"0 0 250 75"</span> <span class="attr">preserveAspectRatio</span>=<span class="string">"xMinYMin slice"</span> <span class="attr">style</span>=<span class="string">"border: 1px solid #cccccc;"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rect</span> <span class="attr">x</span>=<span class="string">"1"</span> <span class="attr">y</span>=<span class="string">"1"</span> <span class="attr">width</span>=<span class="string">"50"</span> <span class="attr">height</span>=<span class="string">"50"</span> <span class="attr">style</span>=<span class="string">"stroke: #000000; fill: none;"</span>&gt;</span><span class="tag">&lt;/<span class="name">rect</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">svg</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p><img src="http://o7bp9e1ec.bkt.clouddn.com/1488694387507" alt="pic_5"><br>这个例子中设置了 preserveAspectRatio 为 xMinYMin slice，同样保留了长宽比，但 view box 根据两个比例中(500/250=2, 75/75=1)较大的比例进行缩放(width: 50*2=100, height: 50*2=100)，结果超过了 viewport 的大小，所以 slice 掉超出的部分。</p>
<h5 id="4"><a href="#4" class="headerlink" title="(4)."></a>(4).</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">svg</span> <span class="attr">width</span>=<span class="string">"500"</span> <span class="attr">height</span>=<span class="string">"75"</span> <span class="attr">viewBox</span>=<span class="string">"0 0 250 75"</span> <span class="attr">preserveAspectRatio</span>=<span class="string">"none"</span> <span class="attr">style</span>=<span class="string">"border: 1px solid #cccccc;"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rect</span> <span class="attr">x</span>=<span class="string">"1"</span> <span class="attr">y</span>=<span class="string">"1"</span> <span class="attr">width</span>=<span class="string">"50"</span> <span class="attr">height</span>=<span class="string">"50"</span> <span class="attr">style</span>=<span class="string">"stroke: #000000; fill:none;"</span>&gt;</span><span class="tag">&lt;/<span class="name">rect</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">svg</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p><img src="http://o7bp9e1ec.bkt.clouddn.com/1488694788943" alt="pic_6"><br>这个例子中设置了 preserveAspectRatio 为 none，view box 将会填满整个 viewport，从而使图像失真，因为x轴和y轴的长宽比不同(x轴 2:1，y轴 1:1)。</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/svg-viewport-view-box/" rel="tag"># svg | viewport | view box</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/02/18/css-centering/" rel="next" title="css-centering">
                <i class="fa fa-chevron-left"></i> css-centering
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/03/07/javascript-array-reduce/" rel="prev" title="javascript-array-reduce">
                javascript-array-reduce <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Overview
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="http://o7bp9e1ec.bkt.clouddn.com/1485173143816"
               alt="Ji Xiang" />
          <p class="site-author-name" itemprop="name">Ji Xiang</p>
          <p class="site-description motion-element" itemprop="description"></p>
        </div>
        <nav class="site-state motion-element">
        
          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">20</span>
                <span class="site-state-item-name">posts</span>
              </a>
            </div>
          

          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">14</span>
                <span class="site-state-item-name">tags</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-The-Viewport-and-View-Box"><span class="nav-number">1.</span> <span class="nav-text">1. The Viewport and View Box</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-svg坐标系单位"><span class="nav-number">2.</span> <span class="nav-text">2. svg坐标系单位</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-The-View-Box"><span class="nav-number">3.</span> <span class="nav-text">3. The View Box</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-Preserving-Aspect-Ratio"><span class="nav-number">4.</span> <span class="nav-text">4. Preserving Aspect Ratio</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1"><span class="nav-number">4.0.1.</span> <span class="nav-text">(1).</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2"><span class="nav-number">4.0.2.</span> <span class="nav-text">(2).</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3"><span class="nav-number">4.0.3.</span> <span class="nav-text">(3).</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#4"><span class="nav-number">4.0.4.</span> <span class="nav-text">(4).</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Ji Xiang</span>
</div>


<div class="powered-by">
  Powered by <a class="theme-link" href="https://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	





  





  

  
      <!-- UY BEGIN -->
      <script type="text/javascript" src="http://v2.uyan.cc/code/uyan.js?uid="></script>
      <!-- UY END -->
  




  
  

  

  

  

  


</body>
</html>
